package cas.ihep.util;

import com.google.common.io.Closer;

import java.io.Closeable;

public class StaticCloser implements Closeable{

    private Closer closer;

    private StaticCloser(){
        closer=Closer.create();
    }

    public <T extends Closeable> T register(T c){
        return closer.register(c);
    }

    public static final StaticCloser instance=new StaticCloser();

    static{
        Runtime.getRuntime().addShutdownHook(new Thread(){
            public void run(){
                instance.close();
            }
        });
    }

    public void close(){
        try{
            closer.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
